package com.java110.mall.cart.cmd.storeOrder;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.CmdContextUtils;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.storeOrder.StoreOrderCartDto;
import com.java110.mall.cart.bmo.storeOrderCart.IGetStoreOrderCartBMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

@Java110Cmd(serviceCode = "storeOrder.queryUserStoreOrderCart")
public class QueryUserStoreOrderCartCmd extends Cmd {

    @Autowired
    private IGetStoreOrderCartBMO getStoreOrderCartBMOImpl;

    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        super.validatePageInfo(reqJson);

    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        String userId = CmdContextUtils.getUserId(context);
        StoreOrderCartDto storeOrderCartDto = BeanConvertUtil.covertBean(reqJson, StoreOrderCartDto.class);

        storeOrderCartDto.setPersonId(userId);
        if (reqJson.containsKey("states")) {
            storeOrderCartDto.setStates(reqJson.getString("states").split(","));
            storeOrderCartDto.setState("");
        }
        ResponseEntity<String> responseEntity = getStoreOrderCartBMOImpl.get(storeOrderCartDto);
        context.setResponseEntity(responseEntity);
    }
}
